package com.example.villagemanager.ui.activity;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.example.villagemanager.R;
import com.example.villagemanager.config.Constant;
import com.example.villagemanager.model.event.Event;
import com.example.villagemanager.ui.adapter.FmPagerAdapter;
import com.example.villagemanager.ui.base.BaseActivity;
import com.example.villagemanager.ui.fragment.person.PermanentFragment;
import com.example.villagemanager.ui.fragment.person.TransientFragment;

import java.util.ArrayList;

import butterknife.BindView;

public class PersonManagerActivity extends BaseActivity {
    @BindView(R.id.listview)
    ListView listView;
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    private ArrayList<Fragment> fragments = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initActivityData() {

    }

    @Override
    protected void initContentView() {

        //准备集合
        String[] data= Constant.person_data;

        //准备适配器ArrayAdapter对象
        ArrayAdapter<String> adapter=new ArrayAdapter<String>
                (this, R.layout.item_array,data);
        //设置adapter显示列表
        listView.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(3);
        fragments=new ArrayList<>();
        PermanentFragment permanentFragment=new PermanentFragment();
        TransientFragment transientFragment=new TransientFragment();
        fragments.add(permanentFragment);
        fragments.add(transientFragment);
        viewPager.setAdapter(new FmPagerAdapter(fragments,getSupportFragmentManager()));
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i<fragments.size()){
                    viewPager.setCurrentItem(i);
                }
            }

        });
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_person_manager;
    }

    @Override
    protected void onEventProcess(Event event) {

    }
}